package com.google.code.jaail

import org.junit.Test
import com.google.code.jaail.networks.ChatNetwork
import static org.mockito.Mockito.*
import static org.mockito.Mockito.when
// uncomment the lines below and alt-enter to grab the artifacts to run this test.
// then comment them again -- intellij and junit dont like grab
//@Grapes(
//    @Grab(group='org.mockito', module='mockito-all', version='1.8.5')
//)
class JaailKeeperTest {
    JaailKeeper underTest = new JaailKeeper()

    @Test
    void "test that when connect is called a connection is opened with a registered network"() {
        ChatNetwork mockChatNetwork = mock(ChatNetwork)
        ChatNetwork mockChatNetworkTwo = mock(ChatNetwork)
        underTest.addChatNetwork(mockChatNetwork)
        underTest.addChatNetwork(mockChatNetworkTwo)

        underTest.connect();

        verify(mockChatNetwork).connect()
        verify(mockChatNetworkTwo).connect()
    }

    @Test
    void "when disconnect is called all connections are closed with registered networks"(){
        ChatNetwork mockChatNetwork = mock(ChatNetwork)
        ChatNetwork mockChatNetworkTwo = mock(ChatNetwork)
        underTest.addChatNetwork(mockChatNetwork)
        underTest.addChatNetwork(mockChatNetworkTwo)

        underTest.disconnect();

        verify(mockChatNetwork).disconnect()
        verify(mockChatNetworkTwo).disconnect()
    }
}
